Func _Game_GameLoop ()
	_Game_LoadAddons ()
	_Map_OpenMap ()
	$bGameLoop = True
	While $bGameLoop
		_Map_DrawMap ()
		If @error Then Exit
	;~ 	_Game_InterpretIncomingData (_BlackCon_Recv ())
		_Game_DrawInterface ()
		_Game_CheckInput ($bGameLoop)
		_Mouse_DrawCursor ()

	 	_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, 800, 600)
		_GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF)
	Wend
EndFunc

Func _Game_CheckInput (ByRef $gameloop)
	If _IsPressed ("1B") Then
		$gameloop = False
		Sleep(100)
		_StartMenu_MenuLoop ()
	EndIf
EndFunc

Func _Game_InterpretIncomingData ($sData)
	$aCommands = StringSplit($sData, @CRLF)
	If Not IsArray ($sData) Then
		$iCommandNumber = 1
	Else
		$iCommandNumber = $aCommands[0]
	EndIf
	For $i = 1 To $iCommandNumber
		$aCommand = StringSplit($aCommands[$i], "|")
		Switch $aCommand[1]
			Case "exit"
				MsgBox(0, "", "Exit")
			Case "kick"
				Exit
		EndSwitch
	Next
EndFunc

Func _Game_DrawInterface ()
	_GDIPlus_GraphicsDrawRect($hBuffer, 0, 0, 799, 599)
	_Game_DrawSpellBoard ()
EndFunc

Func _Game_LoadAddons ()
	$aAddons = _FileListToArray("addons\", "*.wsa")
	For $i = 1 To $aAddons[0]
;~ 		_Game_RunAddon ($aAddons[$i])
		_Write ("Addon " & $aAddons[$i])
	Next
EndFunc

Func _Game_DrawSpellBoard ()
	$iPos = (800 - ($iSpellboardSize * 10)) / 2
	For $i = 0 To 9
		_GDIPlus_GraphicsDrawImageRect($hBuffer, $hSpellShortcutImage, $i *  $iSpellboardSize + $iPos, 600 - $iSpellboardSize, $iSpellboardSize, $iSpellboardSize)
		_GUI_DrawString ($i + 1,  $i *  $iSpellboardSize + $iPos + 3, 600 - $iSpellboardSize + 3)
	Next
EndFunc